# Compile Java project using Maven with Java 17 compatibility
# Check if Maven is installed
Write-Host "Checking for Maven installation..."
if (-not (Get-Command "mvn" -ErrorAction SilentlyContinue)) {
    Write-Host "Maven is not installed. Please install Maven and try again."
    Read-Host "Press Enter to exit..."
    exit 1
}

Write-Host "Compiling project with Maven..."
mvn compile

# Check if compilation succeeded
if ($LASTEXITCODE -eq 0) {
    Write-Host "Compilation successful, starting application..."
    # Run the application using Maven target directory with error logging
    Write-Host "Java classpath: target/classes"
    Write-Host "Main class: com.yololabelmaker.CMainWindow"
    java -cp target/classes com.yololabelmaker.CMainWindow 2>&1 | Write-Host
    if ($LASTEXITCODE -ne 0) {
        Write-Host "Application exited with error code: $LASTEXITCODE"
    }
} else {
    Write-Host "Compilation failed, please check for code errors."
}

Read-Host "Press Enter to exit..."